/*
 * AnimationFrame.java
 * Created by: JakeSamiRulz
 *
 * Organizes frames needed for the AnimationMenu...
 */

package AnimationSystem;

import java.awt.Image;
import java.util.Vector;
import java.awt.Graphics2D;
import ScreenSystem.Screen;
import javax.swing.JComponent;
import ImageSystem.ImageRegistry;

public class AnimationFrame{
    public Vector<ImageHolder> store;//holds image data
    public double locx;//the x location of the image in the frame
    public double locy;//the y location of the image in the frame
    public int maxloop;//The max number before the loop
    
    public int next;//the next frame in the sequence
    private int counter;//How many times it was drawn to the screen
    private double movex;
    private double movey;
    
    
    AnimationFrame(){
        store = new Vector<ImageHolder>();
        counter = 0;
        next = 0;
        maxloop = 1;
        movex = 0;
        movey = 0;
    }
    
    //reurns the next Frame to be drawn
    public boolean nextFrame(Graphics2D g, JComponent screen){
        if(store.get(next).loop > 0){
            if(counter > store.get(next).loop){
                next++;
                if(next >= store.size())
                    next = 0;
                //Find out how much an item moves per frame
                double mx = (store.get(next).finalx-locx);
                double my = (store.get(next).finaly-locy);
                movex = mx/store.get(next).loop;
                movey = my/store.get(next).loop;
                counter = 0;
            }
            //Move the item here...
            counter++;
            
           //Testing movement
            locx += movex;
            locy += movey;
        }
        
        
        Image theImage = ImageRegistry.getImage(store.get(next).theString);
        if(store.get(next).checkZero())
            g.drawImage(theImage,(int)locx,(int)locy,screen);
        else
            g.drawImage(theImage,
                    (int)locx, (int)locy,
                    store.get(next).cutsx,
                    store.get(next).cutsy,
                    store.get(next).cutptx,
                    store.get(next).cutpty,
                    store.get(next).cutsx,
                    store.get(next).cutsy,
                    screen);
        
        return (store.get(next).loop == -1);
    }
    
    public boolean currentFrame(Graphics2D g, JComponent screen){
        if(store.get(next).loop > 0){
           //Testing movement
            locx += movex;
            locy += movey;
        }
        
        Image theImage = ImageRegistry.getImage(store.get(next).theString);
        if(store.get(next).checkZero())
            g.drawImage(theImage,(int)locx,(int)locy,screen);
        else
            g.drawImage(theImage,
                    (int)locx, (int)locy,
                    store.get(next).cutsx,
                    store.get(next).cutsy,
                    store.get(next).cutptx,
                    store.get(next).cutpty,
                    store.get(next).cutsx,
                    store.get(next).cutsy,
                    screen);
        
        return (store.get(next).loop == -1);
    }
}

